﻿@model ProductModel

<div class="panel-group">
    @if (Model.Id > 0)
    {

        <div class="panel panel-default">
            <div class="panel-heading">
                @T("Admin.Catalog.Products.Video.AddNew")
            </div>
            <div class="panel-body">
                <script>
                    var videoId =@(Model.ProductVideo==null?0:Model.ProductVideo.Id);
                    $(document).ready(function () {
                        toastr.options = {
                                closeButton: false,
                                debug: false,
                                progressBar: false,
                                positionClass: "toast-top-center",
                                onclick: null,
                                showDuration: "300",
                                hideDuration: "1000",
                                // timeOut: "1000",
                                extendedTimeOut: "1000",
                                showEasing: "swing",
                                hideEasing: "linear",
                                showMethod: "fadeIn",
                                hideMethod: "fadeOut"
                            };

                        $('#saveProductVideo').click(function () {
                            var videoData = $("#@Html.IdFor(model => model.ProductVideo.ClientJson)").val();
                            $('#saveProductVideo').attr('disabled', true);
                            if (!videoData || videoData == "") {
                                  toastr.info('请上传视频');
                                  return;
                            }
                            var postData = Object.assign({
                                id:videoId,
                                productId: @Model.Id,
                            },JSON.parse(videoData));
                            addAntiForgeryToken(postData);
                            $.ajax({
                                cache: false,
                                type: "POST",
                                url: "@(Url.Action("ProducteVideoUpdate", "Product"))",
                                data: postData,
                                success: function (data) {
                                    debugger
                                    videoId = data.Id;
                                    $('#saveProductVideo').attr('disabled', false);
                                    toastr.success('修改成功');
                                },
                                error: function(xhr, ajaxOptions, thrownError) {
                                    toastr.error('修改失败');
                                    $('#saveProductVideo').attr('disabled', false);
                                }
                            });
                        });
                    });
                </script>
                <div class="form-group">
                    <div class="col-md-3">
                        <nop-label asp-for="ProductVideo.ClientJson" />
                    </div>
                    <div class="col-md-9">
                        <nop-editor asp-for="ProductVideo.ClientJson" />
                        <span asp-validation-for="ProductVideo.ClientJson"></span>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-9 col-md-offset-3">
                        <button type="button" id="saveProductVideo" class="btn btn-primary">@T("Admin.Catalog.Products.Video.SaveButton")</button>
                    </div>
                </div>
            </div>
        </div>
    }
    else
    {
        <div class="panel panel-default">
            <div class="panel-body">
                @T("Admin.Catalog.Products.Video.SaveBeforeEdit")
            </div>
        </div>
    }

</div>